package com.yanqu.road.server.cmd.activity.xiuxian.cross;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.activity.XiuXianProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.activity.ActivityModule;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.GameProtocol;
import io.netty.channel.ChannelHandlerContext;

@Cmd(code = GameProtocol.S_XIU_XIAN_NOTIFY_CONDITION_FROM_CROSS, desc = "同步condition更新  跨服返回")
public class XiuXianNotifyConditionFromCrossCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage packet) throws Exception {
        XiuXianProto.CrossXiuXianNotifyConditionRespMsg respMsg = XiuXianProto.CrossXiuXianNotifyConditionRespMsg.parseFrom(packet.getBytes());
        GamePlayer onlinePlayer = GamePlayerMgr.getOnlinePlayer(respMsg.getUserId());
        if (onlinePlayer != null) {
            onlinePlayer.getModule(ActivityModule.class).startChanges();
            onlinePlayer.notifyListener(respMsg.getConditionType(), respMsg.getValue());
            onlinePlayer.getModule(ActivityModule.class).finishChanges();
        }
    }

}
